"""
写一个用户注册小程序，
要求用户在控制台输入“ID”、“EMAIL地址”、“身份证号”、“姓名
"""

# 判断id_number输入的合法性
id_number = ''
flag = True
while flag:
    id_number = input('请输入你的ID:\n').strip()
    if len(id_number) >= 8 or len(id_number) == 0:
        print('id长度不能大于8或者为空，请重新输入\n')
        continue
    is_valid = True
    for i in id_number:
        if i.isdigit() or i.isalpha() or i == '_':
            continue
        else:
            is_valid = False
            print('输入的id包含非法字符，请重新输入\n')
            break
    if is_valid:
        flag = False

email = ''
email_flag = True
while email_flag:
    email = input('请输入你的电子邮件:\n')
    if '@' not in email:
        print('您的邮箱格式不正确，请重新输入')
    else:
        email_flag = False

last = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'X']
id_card = ''
id_card_flag = True
while id_card_flag:
    id_card = input('请输入你的身份证号:\n')
    prefix = id_card[0:-2]
    if len(id_card) != 18:
        print('您输入的身份证长度不正确，请重新输入\n')
        continue
    elif not id_card[-2].isdigit():
        print('您输入的身份证字符不正确，请重新输入\n')
        continue
    elif id_card[-1] not in last:
        print('您输入的身份证字符不正确，请重新输入\n')
        continue
    else:
        id_card_flag = False


def is_chinese(text):
    """判断输入的的参数是否是包含中文的函数"""
    try:
        return all(char.isalpha() and char.encode('gbk') for char in text)
    except UnicodeEncodeError:
        return False


name = ''
name_flag = True
while name_flag:
    name = input('请输入你的姓名:\n')
    if len(name) > 4:
        print('您的名字长度不能超过4，请重新输入!')
    else:
        if is_chinese(name):
            name_flag = False
        else:
            print('您输入的名字包含非中文字符，请重新输入')

if int(id_number[-2]) % 2 == 0:
    gender = '男'
else:
    gender = '女'

print(f'您的ID为： {id_number}, 您的电子邮件为: {email}, 您的身份证为: {id_number}, 您的姓名为: {name}， 性别为： {gender}')
